package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

/*
[DEBUG] [2024/04/28 23:33:48] [PRJ/websocket_apn/main_test.go]:[  196]:   S_HERORANK_GET_FIGHT_LIST - id:3109673861602
[DEBUG] [2024/04/28 23:33:48] [PRJ/websocket_apn/main_test.go]:[  197]:   PayloadBytes: 71 AB 00 00 00 14 00 00 5C 96 00 00 02D4 07 01 81 E2 08 00
*/
func (xd *XdDriver) CheckAllHeroInfoData(allInfo D.AllHeroInfo) {
	inFront := true
	if len(allInfo.Hero) > 0 {
		for i, info := range allInfo.Hero {
			if i < 3 {
				continue
			}
			if info.ID == xd.UserData.UserID {
				inFront = false
				continue
			}
			if inFront {
				if info.CombatValue*10 > xd.UserData.FightInfo.CombatValue*8 {
					continue
				} else if info.Ranking < 10 {
					log.Infof("开始挑战群英榜第%d名 [%s] 战力 %s", info.Ranking, info.Name, D.GetCombatValueDesc(info.CombatValue))
					if info.NotHuman {
						xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_HERORANK_FIGHT, fmt.Sprintf("08 00 10 %s 18 %s 20 %s 28 %s 30 %s",
							info.RankStr, info.R18, info.R20, info.R28, info.R30)))
					} else {
						xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_HERORANK_FIGHT, fmt.Sprintf("08 %s 10 %s 18 00 20 00 28 00 30 00", info.ID, info.RankStr)))
					}
					break
				}
			} else {
				log.Infof("开始速战群英榜第%d名 [%s] 战力 %s ", info.Ranking, info.Name, D.GetCombatValueDesc(info.CombatValue))
				xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_HERORANK_CLEAR, fmt.Sprintf("080010%s18%s", info.ID, info.RankStr)))
			}
		}
	}
	if allInfo.FightCount > 0 {
		task := xd.GetTaskByID(proto.S_HERORANK_ENTER)
		task.LastRun = time.Now().Add(-23 * time.Hour)
	}
}
